package com.achen.service.impl;

import com.achen.dao.UserDao;
import com.achen.elasticsearch.dao.UserRepository;
import com.achen.entity.User;
import com.achen.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.UUID;

/**
 * @author achen
 * @create 2020-05-04 1:27
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Autowired
    private UserRepository userRepository;

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public void save(User user) {
        user.setId(UUID.randomUUID().toString());
        userDao.save(user);
    }

    @Override
    public void del(String id) {
        userDao.del(id);
    }

    @Override
    public User findOne(String id) {
        return userDao.findOne(id);
    }

    @Override
    public void edit(User user) {
        userDao.edit(user);
    }

    @Override
    public List<User> findBySearch(String querykeyword) {
        return userRepository.findBySearch(querykeyword);
    }
}
